/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#buyStartTime").val(_start);
$("#buyEndTime").val(_end);
laydate.render({
    elem: '#buyStartTime',
    type: 'datetime'

});
laydate.render({
    elem: '#buyEndTime'
    , type: 'datetime'
});
buttonShiro("export_Role");
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/supplyCard/findSupplyCardDetailPage',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    singleSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.total,
            "rows": res.resultList
        };
    },
    onClickRow: function (row) {
        if (row.userAccount != null && row.userAccount != '') {
            $("#account_field" + row.orderId).html(row.userAccount);
        }
    },
    columns: [
        {
            checkbox: true
        },
        {
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {
            align: 'center',
            field: 'orderId',
            width: 150,
            title: '订单号'
        }, {
            align: 'center',
            field: 'batchId',
            title: '批次号'
        },
        {
            align: 'center',
            field: 'cardNumber',
            title: '卡号'
        }, {
            align: 'center',
            field: 'cardOperatorName',
            title: '运营商类型'
        }, {
            align: 'center',
            field: 'userAccount',
            title: '会员编号',
            formatter: function (v, o) {
                return copyAddon(v) + (adminRole == 1 ? v : userAccountHidden(o.userAccount, o.orderId));
            }
        }, {
            align: 'center',
            field: 'userName',
            title: '会员名称'
        }, {
            align: 'center',
            field: 'startTime',
            title: '记录时间'
        }, {
            align: 'center',
            field: 'channel',
            title: '提现渠道',
            formatter: function (v, row, index) {
                return withdrawChannel[v];
            }
        }, {
            align: 'center',
            field: 'consumeType',
            title: '消费类型',
            formatter: function (v, row, index) {
                return consumeType[v];
            }
        }, {
            align: 'center',
            field: 'money',
            title: '消费金额'
        }, {
            align: 'center',
            field: 'balance',
            title: '余额'
        }
    ],
});

$("#search").click(function () {
    var timeAdd = new Date($("#buyStartTime").val());
    var timeEnd = new Date($("#buyEndTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    $("#dataTable").bootstrapTable("refresh");
});
//下载
$("#export").click(function () {
    window.location.href = "/supplyCard/supplyCardDetailDownLoad?" + $("#supplyCardDetailForm").serialize()
})
$(function () {
    $.ajax({
        type: "POST",
        url: "/CardProductController/queryAllCardOperatorList",
        dataType: "json",
        success: function (data) {
            $("#productType").html("");
            var str = "<option value=\"\">全部</option>";
            if (data != null && data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    str += '<option value=' + data[i].cardOperatorId + '>' + data[i].cardOperatorName + '</option>'
                }
            }
            $("#productType").append(str);
            //缺一不可  
            $('.selectpicker').selectpicker('refresh');
            $('.selectpicker').selectpicker('render');
        },
        beforeSend: function () {
        }
    });
})

function queryParams(params) {
    return {
        'pageUnit.size': params.pageSize,
        'pageUnit.page': params.pageNumber,
        userAccount: $.trim($("#userAccount").val()),
        batchId: $("#batchId").val(),
        orderId: $("#orderId").val(),
        cardNumber: $("#cardNumber").val(),
        productType: $("#productType").val(),
        type: $("#type").val(),
        startTime: $("#buyStartTime").val(),
        endTime: $("#buyEndTime").val(),
    };
}
